package com.treasuremall.auth.config;

import com.treasuremall.auth.constant.OauthTokenConstant;
import com.treasuremall.auth.jwt.JwtTokenEnhancer;
import lombok.AllArgsConstructor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.security.oauth2.provider.token.TokenEnhancer;
import org.springframework.security.oauth2.provider.token.TokenStore;
import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter;
import org.springframework.security.oauth2.provider.token.store.JwtTokenStore;
import org.springframework.security.oauth2.provider.token.store.redis.RedisTokenStore;

/**
 * 一句话描述功能
 *
 * @author 时前程
 * @create 2020-02-25 21:55
 * @Version V1.0
 **/
@Configuration
@ConditionalOnProperty(prefix = "treasure.security.oauth2",name = "storeType",havingValue = "jwt",matchIfMissing = true)
public class JwtTokenStoreConfig{

    @Bean
    public TokenStore tokenStore(){
        return new JwtTokenStore(tokenConverter());
    }

    @Bean("jwtAccessTokenConverter")
    public JwtAccessTokenConverter tokenConverter(){
        JwtAccessTokenConverter accessTokenConverter = new JwtAccessTokenConverter();
        accessTokenConverter.setSigningKey(OauthTokenConstant.JWTSIGNKEY);
        return accessTokenConverter;
    }
}
